﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Register.Command;
using Register.DALFactory;
using Register.IDAL;
using Register.Model;
using System.Data;
namespace Register.BLL
{
    /// <summary> 
    /// FileName: DoctorInfoBLL.cs    
    /// CLRVersion: 4.0.30319.269    
    /// Author: DoubleZ    
    /// Corporation:     
    /// Description:     
    /// DateTime: 2012/6/29 20:34:10    
    /// </summary>
  public   class DoctorInfoBLL
    {
      private static String typeNameKey = "IDoctorInfoDALKey";
        #region 添加医生信息
      public static bool AddDoctorInfo(Model.DoctorInfo model)
      {
          IDoctorInfoDAL iDoctorInfo = DALFactory<IDoctorInfoDAL>.Create(typeNameKey);
          try
          {
            if (iDoctorInfo.AddDoctorInfo(model)>0)
                  return true;
              else
                  return false;
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }
        #endregion
        #region 获取科室信息
        public static List<DepartmentsInfo> GetDepartmentsList()
        {
          try
          {
              IDoctorInfoDAL iParamter = DALFactory<IDoctorInfoDAL>.Create(typeNameKey);

              return iParamter.GetDepartmentsList();
          }
          catch (Exception e)
          {
              LogRecordHelper.LogNote("ERROR", e.Message);
              throw e;
          }
      }

        #endregion
        #region 获取医生信息
       public static List<DoctorInfo> DataTableToList(DataTable dt)
        {   
            List<DoctorInfo> modelList = new List<DoctorInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                DoctorInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new DoctorInfo();
                    model.Doctor_ID= dt.Rows[n]["Doctor_ID"].ToString();
                    model.Departments_ID= dt.Rows[n]["Departments_ID"].ToString();
                    model.Doctor_No= dt.Rows[n]["Doctor_No"].ToString();
                    model.Doctor_Name= dt.Rows[n]["Doctor_Name"].ToString();
                    model.Doctor_Gender = dt.Rows[n]["Doctor_Gender"].ToString();
                    model.Doctor_DateOfBirth = (DateTime)dt.Rows[n]["Doctor_DateOfBirth"];
                    model.Doctor_Position= dt.Rows[n]["Doctor_Position"].ToString();
                    model.Doctor_Education = dt.Rows[n]["Doctor_Education"].ToString();
                    model.Doctor_Specialty= dt.Rows[n]["Doctor_Specialty"].ToString();
                    model.Doctor_Resume = dt.Rows[n]["Doctor_Resume"].ToString();
                    model.Doctor_Phone = dt.Rows[n]["Doctor_Phone"].ToString();
                    model.Doctor_Email = dt.Rows[n]["Doctor_Email"].ToString(); 
                    model.Doctor_Picture = dt.Rows[n]["Doctor_Picture"].ToString();
                   model.Doctor_AddTime = (DateTime)dt.Rows[n]["Doctor_AddTime"];
                   model.Doctor_Recoder= dt.Rows[n]["Doctor_Recoder"].ToString();
                   model.Doctor_State= dt.Rows[n]["Doctor_State"].ToString();
                   modelList.Add(model);
                }
            }
            return modelList;
        }
       public static Model.DoctorInfo GetDoctorInfo(string doctorID)
       {
           IDoctorInfoDAL iDoctorInfo = DALFactory<IDoctorInfoDAL>.Create(typeNameKey);
           try
           {
               return iDoctorInfo.GetDoctorInfo(doctorID);
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }

       public static List<Model.DoctorInfo> GetPagedDoctorInfo(int size, int pageIndex, string where)
       {
           IDoctorInfoDAL iDoctorInfo = DALFactory< IDoctorInfoDAL>.Create(typeNameKey);
           try
           {
               return  iDoctorInfo.GetPagedDoctorInfo(size,pageIndex,where);
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }
       public static int GetDoctorInfoCount(string where)
       {
          IDoctorInfoDAL iDoctorInfo = DALFactory<  IDoctorInfoDAL>.Create(typeNameKey);

           try
           {
               return  iDoctorInfo.GetDoctorInfoCount(where);
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }
        #endregion  Methodb
       #region 更新医生
       public static bool UpdateDoctorInfo(Model.DoctorInfo model)
       {
           IDoctorInfoDAL iDoctorInfo = DALFactory<IDoctorInfoDAL>.Create(typeNameKey);
           try
           {
               if (iDoctorInfo.UpdateDoctorInfo(model)> 0)
               {
                   return true;
               }
               else
                   return false;
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }
        
       #endregion
       #region 删除医生
       public static bool DeleteDoctorInfo(string doctorID)
       {
          IDoctorInfoDAL iDoctorInfo = DALFactory<IDoctorInfoDAL>.Create(typeNameKey);
           try
           {
               if (iDoctorInfo.DeleteDoctorInfo(doctorID) > 0)
                   return true;
               else
                   return false;
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }
       #endregion
       #region 获取性别名称
     /*  public static string GetGenderNameById(string paramID)
       {
           IDoctorInfoDAL iDoctorInfo = DALFactory<IDoctorInfoDAL>.Create(typeNameKey);
           try
           {
               return iDoctorInfo.GetGenderNameById(paramID);

           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }*/
        #endregion
        #region 根据科室ID获取科室名称
       public static string GetDepartmentsNameById(string departmentsID)
       {
           IDoctorInfoDAL iCityInfo = DALFactory<IDoctorInfoDAL>.Create(typeNameKey);
           try
           {
               return iCityInfo.GetDepartmentsNameById(departmentsID);

           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }
        #endregion
       #region 检查医生是否存在用户
       public static bool Exists(string doctorID)
       {
           IDoctorInfoDAL iDoctorInfo = DALFactory<IDoctorInfoDAL>.Create(typeNameKey);

           try
           {
               bool flag = iDoctorInfo.Exists(doctorID);
               return flag;
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }

       #endregion

    }
}


 

